DYN = 1

ifndef PROOT
PROOT = ../curl-7.40.0-devel-mingw32
endif

ifndef ARCH
ARCH = w32
endif

CC	= $(CROSSPREFIX)gcc
CFLAGS	= -g -O2 -Wall
CFLAGS	+= -fno-strict-aliasing

ifeq ($(ARCH),w64)
CFLAGS	+= -D_AMD64_
LIBSFX	= 64
endif

INCLUDES = -I. -I$(PROOT) -I$(PROOT)/include
# comment LDFLAGS below to keep debug info
LDFLAGS	= -s

ifdef DYN
  curl_DEPENDENCIES = $(PROOT)/lib$(LIBSFX)/libcurldll.a $(PROOT)/bin/libcurl.dll
  curl_LDADD = -L"$(PROOT)/lib$(LIBSFX)" -lcurldll
else
  curl_DEPENDENCIES = $(PROOT)/lib$(LIBSFX)/libcurl.a
  curl_LDADD = -L"$(PROOT)/lib$(LIBSFX)" -lcurl
  CFLAGS += -DCURL_STATICLIB
  LDFLAGS += -static
endif


check_PROGRAMS := $(patsubst %.c,%.exe,$(wildcard *.c))
check_OBJECTS := $(check_PROGRAMS:.exe=.o)

.SUFFIXES: .rc .res
.PRECIOUS: %.o

#all: $(check_PROGRAMS)
all:kuwo.c base64.cpp base64.h $(curl_DEPENDENCIES)
	gcc -o kuwonew kuwo.c base64.cpp $(INCLUDES) $(curl_LDADD) -liconv

%.exe: %.o $(curl_DEPENDENCIES)
	$(CC) $(LDFLAGS) -o $@ $< $(curl_LDADD)

.c.o:
	$(CC) $(INCLUDES) $(CFLAGS) -c $<


clean:
	@del $(check_PROGRAMS) $(check_OBJECTS)

